#include "openMVG/image/image_io.hpp"
#include "openMVG/image/image_concat.hpp"
#include "openMVG/features/akaze/image_describer_akaze.hpp"
#include "openMVG/features/sift/SIFT_Anatomy_Image_Describer.hpp"
#include "openMVG/features/svg_features.hpp"
#include "openMVG/matching/regions_matcher.hpp"
#include "openMVG/matching/svg_matches.hpp"

#include <memory>
#include <string>
#include "openMVG/third_party/stlplus3/filesystemSimplified/file_system.hpp"

using namespace std  ;
using namespace openMVG;
using namespace openMVG::image;

int main()
{
    const string  data_root="/root/code/3dRe/data/projectData/test1/";
    const string img1_filename="VID_20210614_141105_00_006_000001.jpg";
    const string img2_filename="VID_20210614_141105_00_006_000241.jpg";


    Image<unsigned char> img1,img2;
    ReadImage((data_root+img1_filename).c_str(),&img1);
    ReadImage((data_root+img2_filename).c_str(),&img2);

    assert(img1.data() && img2.data());

    using namespace openMVG::features;
    std::unique_ptr<Image_describer> image_describer;
    image_describer.reset(new SIFT_Anatomy_Image_describer(SIFT_Anatomy_Image_describer::Params()));

  std::map<IndexT, std::unique_ptr<features::Regions>> regions_perImage;
  image_describer->Describe(img1, regions_perImage[0]);
  image_describer->Describe(img2, regions_perImage[1]);


    matching::IndMatches vec_PutativeMatches;
  matching::DistanceRatioMatch(
    0.8, matching::BRUTE_FORCE_L2,
    *regions_perImage.at(0).get(),
    *regions_perImage.at(1).get(),
    vec_PutativeMatches);
    const bool bVertical = true;
    Matches2SVG
    (
      data_root+img1_filename,
      {img1.Width(), img1.Height()},
      regions_perImage.at(0)->GetRegionsPositions(),
      data_root+img2_filename,
      {img2.Width(), img2.Height()},
      regions_perImage.at(1)->GetRegionsPositions(),
      vec_PutativeMatches,
      "/root/code/3dRe/data/output/02_Matches.svg",
      bVertical
    );
  std::cout
    << regions_perImage.at(0)->RegionCount() << " #Features on image A" << std::endl
    << regions_perImage.at(1)->RegionCount() << " #Features on image B" << std::endl
    << vec_PutativeMatches.size() << " #matches with Distance Ratio filter" << std::endl;
}